// Install script for helloworld

var err;
const APP_VERSION="0.0.0.1";//版本号

//初始化安装
err = initInstall("helloworld"+APP_VERSION,  // name for install UI
                  "/helloworld",               // registered name
                  APP_VERSION);              // package version
if(err!=0)
{//安装出错，取消安装
	cancelInstall(err);
}

//标准目录
var fProgram = getFolder("Program");//程序根目录 
var fChrome     = getFolder("Chrome");//chrome目录
var fComponents = getFolder("Components");//components目录

// workaround for Mozilla 1.8a3 and newer, failing to register enigmime correctly
var delComps = [ "compreg.dat" ]; // Components registry
for (var j=0; j<delComps.length; j++)
{
     var delFile = getFolder(fComponents, delComps[j]);
     if (File.exists(delFile))
        File.remove(delFile);
}

err = getLastError();
if (err == DOES_NOT_EXIST)
{
    // error code: file does not exist
    resetError();
}
else if (err != SUCCESS) 
{
    cancelInstall(err);
}

// addDirectory: blank, archive_dir, install_dir, install_subdir
addDirectory("", "components",    fComponents, "");
addDirectory("", "chrome",        fChrome,     "");


err = getLastError();
if (err == ACCESS_DENIED)
{
    alert("Unable to write to components directory "+fComponents+".\n You will need to restart the browser with administrator/root privileges to install this software. After installing as root (or administrator), you will need to restart the browser one more time, as a privileged user, to register the installed software.\n After the second restart, you can go back to running the browser without privileges!");
    cancelInstall(ACCESS_DENIED);

} 
else if (err != SUCCESS)
{
    cancelInstall(err);

} 
else 
{
    // Register chrome
    registerChrome(PACKAGE | DELAYED_CHROME, getFolder("Chrome","helloworld.jar"), "content/helloworld/");
    err = getLastError();
    if (err != SUCCESS)
	{
      cancelInstall(err);
    }
	else
	{
      performInstall();
    }
}
